﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SW_SoftBully.Controllers;
using SW_SoftBully.Models.ModuloAdministracion.Cargo;
using System.Data.SqlClient;
using log4net;

namespace SW_SoftBully.Models.ModuloAdministracion.Cargo
{
    public class CargoDAO
    {
        public List<CargoBean> ListarCargo(CargoBean cargo)
        {
            try
            {
                List<CargoBean> listaCargo = new List<CargoBean>();

                String cadenaConfiguracion = ConfigurationManager.ConnectionStrings["SoftBully"].ConnectionString;

                SqlConnection sqlCon = new SqlConnection(cadenaConfiguracion);

                sqlCon.Open();

                string commandString = "SELECT * FROM Cargo WHERE estado = 1"; 

                SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);

                SqlDataReader dataReader = sqlCmd.ExecuteReader();

                while (dataReader.Read()){
                        CargoBean Cargo = new CargoBean();
                        Cargo.Id_Cargo = Convert.ToInt32(dataReader["Id_Cargo"]);
                        Cargo.Descripcion = Convert.ToString(dataReader["Descripcion"]);
                        Cargo.Estado = Convert.ToInt32(dataReader["Estado"]);
                        Cargo.Categoria = Convert.ToString(dataReader["categoria"]);
                        listaCargo.Add(Cargo);                   
                }
                dataReader.Close();
                sqlCon.Close();

                return listaCargo;
            }
            catch (Exception e)
            {
                String men = e.ToString();
                cargo.conexion = men;
                return null;
            }
        }
    }
}